import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/layout/IndexView.vue'

// 为什么要用路由懒加载？
// 有时我们并不需要所有的路由对应的组件都加载，当匹配时再去加载对应的组件

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: 'user',
        component: () => import('@/views/user/indexView.vue'),
      },
      {
        path: 'user/create',
        component: () => import('@/views/user/createView.vue'),
      },
    ],
  },
  {
    path: '/login',
    component: () => import('@/views/login/indexView.vue'),
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})

export default router
